package com.situ.mall.controller.back;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.situ.mall.entity.Category;
import com.situ.mall.entity.Product;
import com.situ.mall.service.ICategoryService;
import com.situ.mall.service.IProductService;
import com.situ.mall.util.JSONResult;
import com.situ.mall.util.LayUITableResult;

@Controller
@RequestMapping("/product")
public class ProductController {
	@Autowired
	private IProductService productService;
	@Autowired
	private ICategoryService categoryService;
	
	@RequestMapping("/selectAll")
	@ResponseBody
	public List<Product> selectAll() {
		List<Product> list = productService.selectAll();
		return list;
	}
	
	@RequestMapping("/selectByPage")
	@ResponseBody
	public LayUITableResult selectByPage(Integer page, Integer limit) {
		LayUITableResult layUITableResult = productService.selectByPage(page, limit);
		return layUITableResult;
	}
	
	@RequestMapping("/getProductInsertPage")
	public String getProductInsertPage(Model model) {
		List<Category> topCategoryList = categoryService.selectTopCategoryList();
		model.addAttribute("topCategoryList", topCategoryList);
		return "/jsp/back/product_insert.jsp";
	}
	
	@RequestMapping("/insert")
	@ResponseBody
	public JSONResult insert(Product product) {
		productService.insert(product);
		return JSONResult.ok("插入成功");
	}
}
